﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LogLib
{
    public class LogInfo
    {
        public string LogFullName 
        { 
            get;
            set; 
        }

        public string Content
        {
            get;
            set; 
        }

        public LogInfo()
        {
            LogFullName = "";
            Content = "";
        }

        public LogInfo(string fullName, string content)
        {
            LogFullName = fullName;         
            Content = content;
        }

        public bool IsEmpty()
        {
            return string.IsNullOrEmpty(LogFullName) || string.IsNullOrEmpty(Content);
        }

        public void SetNull()
        {
            LogFullName = "";
            Content = "";
        }
    }

    public class LogInfoList
    {
        public string LogFullName = "";
       
        public List<string> ListLines = new List<string>();

        public LogInfoList(string fullName, List<string> list)
        {
            LogFullName = fullName;
            ListLines = list;
        }

        public void SetNull()
        {
            LogFullName = "";
            ListLines.Clear();
        }

        public bool IsEmpty()
        {
            return ListLines == null || string.IsNullOrEmpty(LogFullName) || ListLines.Count == 0;
        }

        public string GetStrings()
        {
            if (IsEmpty())
            {
                return "";
            }
            StringBuilder buildString = new StringBuilder();
            if (ListLines.Count <= 3)
            {
                for (int i = 0; i < ListLines.Count; i++)
                {
                    buildString.Append(ListLines[i]);
                    if (i < ListLines.Count - 1)
                    {
                        buildString.Append("; ");
                    }
                    else
                    {
                        buildString.Append(".");
                    }
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    buildString.Append(ListLines[i]);
                    if (i < ListLines.Count - 1)
                    {
                        buildString.Append("; ");
                    }
                    else
                    {
                        buildString.Append("等等.");
                    }
                }
            }
            return buildString.ToString();
        }
    }

    /// <summary>
    /// 异步任务运行状态
    /// </summary>
    public enum AsyncTaskState : uint
    {
        /// <summary>
        /// 未初始化
        /// </summary>
        Uninitialized = 0,
        /// <summary>
        /// 等待执行
        /// </summary>
        Waiting = 1,
        /// <summary>
        /// 正在执行
        /// </summary>
        Running = 2,
        /// <summary>
        /// 已终止
        /// </summary>
        Terminated = 4
    }

    /// <summary>
    /// 报告写日记错误事件
    /// </summary>
    public class LogErrorReportedEventArgs : EventArgs
    {
        public readonly LogInfo ErrorObject;

        public readonly string ErrorMessage;

        public LogErrorReportedEventArgs(LogInfo info, string message)
        {
            this.ErrorObject = info;
            this.ErrorMessage = message;
        }
    }

    // 日记错误事件委托
    public delegate void LogErrorReportedEventHandler(Object sender, LogErrorReportedEventArgs e);
}
